package com.example.pixelyear.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.pixelyear.R
import com.example.pixelyear.utils.extension.setOnDoubleClickListener
import kotlinx.android.synthetic.main.item_indictor.view.*

class IndicatorAdapter(val context: Context) : BaseAdapter<Int>() {
    var lastChoose = 0
    var nowChoose = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        return BaseViewHolder(LayoutInflater.from(context).inflate(R.layout.item_indictor, parent, false))
    }

    override fun onBindView(itemView: View, bean: Int, position: Int) {
        if (nowChoose == position) {
            itemView.Item_Indictor.setBackgroundResource(R.drawable.blue_round)
        } else {
            itemView.Item_Indictor.setBackgroundResource(R.drawable.gray_round)
        }

        itemView.setOnDoubleClickListener {
            onItemClick?.click(bean, position)
        }
    }

    fun updatePosition(index: Int) {
        nowChoose = index
        notifyItemChanged(nowChoose)
        if (lastChoose != -1)
            notifyItemChanged(lastChoose)
        lastChoose = index
    }


}
